
/***************************************************************************************************************************

This part of the dofile is our code: Create Z, D, Y, and globals per application

***************************************************************************************************************************/

cd "$INDTA"

use panel_clean_final.dta, clear

***Data prep for main analysis
gen z=treatment
			
gen d1=in_linkedin
gen d2=in_linkedin6month

gen y=employed3_all

gen noweight=1

egen 	allfe=rowtotal(stratum*)
assert 	allfe==1
drop 	allfe

global controls		stratum2 stratum3 stratum4 stratum5 stratum6 stratum7 stratum8 ///
					stratum9 stratum10 stratum11 stratum12 stratum13 stratum14
global weight		noweight
global clustervar	studref

global controls_s12 stratum2_s1 stratum2_s2 stratum3_s1 stratum3_s2 stratum4_s1 stratum4_s2 stratum5_s1 stratum5_s2 ///
					stratum6_s1 stratum6_s2 stratum7_s1 stratum7_s2 stratum8_s1 stratum8_s2 stratum9_s1 stratum9_s2 ///
					stratum10_s1 stratum10_s2 stratum11_s1 stratum11_s2 stratum12_s1 stratum12_s2 ///
					stratum13_s1 stratum13_s2 stratum14_s1 stratum14_s2

***Data prep for analysis per x
gen everyonex2=1
gen everyonex3=1

gen clusterid=_n

global controlsx1 	stratum1 stratum2 stratum3 stratum4 stratum5 stratum6 stratum7 stratum8 ///
					stratum9 stratum10 stratum11 stratum12 stratum13 stratum14
global controlsx2	everyonex2
global controlsx3	everyonex3					
						
global clustervarx 	clusterid							

***Keep if y not missing
keep if y!=.



/*************************************************************************************************************************** 
***Appendix: Replicate Table 2 of Wheeler et al. (2022)
***Run before keep if y!=. for exact results

eststo: reghdfe li_account treatment, absorb(strata) cluster( $clustervar )
eststo: reghdfe account_in_bridge treatment, absorb(strata) cluster( $clustervar )
eststo: reghdfe summary_li_pca treatment, absorb(strata) cluster( $clustervar )

esttab, keep(treatment) b(3) se(3) nostar nonotes label title("Replication of Table 2 Wheeler et al. (2022)")
eststo clear

eststo: reg li_account treatment $controls, cluster( $clustervar) 
eststo: reg account_in_bridge treatment $controls, cluster( $clustervar) 
eststo: reg summary_li_pca treatment $controls, cluster( $clustervar) 

esttab, keep(treatment) b(3) se(3) nostar nonotes label title("Replication of Table 2 Wheeler et al. (2022)")
eststo clear


***Replicate Figure B.1 of Wheeler et al. (2022)

preserve

keep treated in_linkedin in_linkedin6month in_linkedin12month studref in_lix
	
rename in_linkedin li_account1
rename in_linkedin6month li_account2
rename in_linkedin12month li_account3
replace li_account3=in_lix if studref>=17
	
drop studref in_lix
gen id=_n

reshape long li_account, i(id) j(pull)
	
xtset id pull
collapse (mean) li_account, by(treated pull)
xtset treated pull	
label define treated 0 "Control" 1 "Treatment"
label val treated treated

replace pull=6 if pull==2
replace pull=12 if pull==3

foreach v in li_account {
	summ `v' if treated==1&pull==12, d
	global `v'_t=r(max)
	summ `v' if treated==0&pull==12, d
	global `v'_c=r(max)
}

xtline li_account, overlay legend(off) xlabel(1 6 12) ylabel(0 0.25 0.5 0.75) ///
		plot1(text($li_account_c 13 "C", color(blue)) lc(blue)) ///
		plot2(text($li_account_t 13 "T", color(red)) lc(red) lp(dash)) xtitle("Month") ///
		ytitle("") title("LinkedIn Account") graphregion(color(white) lwidth(thick)) 

restore
***************************************************************************************************************************/

